$(function(){
	//maxlength="80"
	//$("input[type='text']").attr("maxlength","80");
	$("textarea").attr("maxlength","1000");
	var pagePath = $("#pagePath").val();
	uploadFile.excel({context:".first",url:pagePath+'/settings/user/importData.json',progress:pagePath+"/comm/uploadProgress.json",progressFn:progressFn,success:successFn});
	//全选或全不选
	 $("span[name=checkAll]").live("click",function(){
	        var booleanParentSelect=$("span[name=checkAll]").children().hasClass("active");
	        if(!booleanParentSelect){
	        	$("span[name=checkSingle]").children().removeClass("active");
	        }else{
	        	$("span[name=checkSingle]").children().addClass("active");
	        }
	    });
	 //点击子项的选择
	 $("span[name=checkSingle]").live("click",function(){
		 if($("span[name=checkSingle]").children().length > 0){
				var count = 0;
				for (var int = 0; int < $("span[name=checkSingle]").children().length; int++) {
					if($("span[name=checkSingle]").children().eq(int).hasClass("active")){
						count ++;
					}
				}
				if($("span[name=checkSingle]").children().length == count){
					$("span[name=checkAll]").children().addClass("active");
				}else{
					$("span[name=checkAll]").children().removeClass("active");
				}
			}
	 });
});
var pagePath = $("#pagePath").val();
var resourcePath = $("#resourcePath").val();
/**
 * 
 * @Title: searchUser   
 * @Description: 查询用户
 * @param:       
 * @return: void      
 * @throws
 */
function searchUser(obj){
	$("#searchBody").html("");
	var html="";
	var username = $("#JQ_username").val();
	var companyId = $("#SCompDiv").children().attr("id");
	var departmentId = $("#SDeptDiv").children().attr("id");
	var isAuthorize = $("#authorDiv").children().attr("id");
	if("gs" == companyId){
		companyId = "";
	}
	if("bm" == departmentId){
		departmentId = "";
	}
	var data = {"username":username,"companyId":companyId,"departmentId":departmentId,"isAuthorize":isAuthorize};
	$().invoke(pagePath + "/settings/user/searchUser.json",data,[function(m,r){
		if(r.length < 1){
			html += "<div class='no-data '><img src='"+resourcePath+"/images/pig/no-data.png' alt=''/></div>";
		}else{
			$.each(r,function(i,evalue){
				var hangClass = 'ul-header bg-white';
			    if(i % 2 != 0){
			        hangClass = 'ul-header bg-second';
			    }
			    var stateClass = '';
			    if('LOCKED' == evalue.state){
			    	stateClass = 'on-off';
			    }else if('ACTIVATE' == evalue.state){
			    	stateClass = 'on-off active';
			    }
			    
			    html += "<div class='info-tr'>" +
							"<ul class= '"+hangClass+"'>" +
								"<li class='w5'  style='width:5%'><span class='table-ck'><span name='checkSingle' class='check-box selected' id='"+evalue.id+"'><i></i></span></span></li>" +
								"<li class='w15-2' style='width:10%' title='"+convertObjectToString(evalue.username)+"'>"+convertObjectToString(evalue.username)+"</li>" +
								"<li class='sw10-6' style='width:10%' title='"+convertObjectToString(evalue.realName)+"'>"+convertObjectToString(evalue.realName)+"</li>" +
								"<li class='w10'  style='width:5%' title='"+convertObjectToString(evalue.sex)+"'>"+convertObjectToString(evalue.sex)+"</li>" +
								"<li class='w10'  style='width:10%' title='"+convertObjectToString(evalue.email)+"'>"+convertObjectToString(evalue.email)+"</li>" +
								"<li class='w10'  style='width:10%' title='"+convertObjectToString(evalue.mobile)+"'>"+convertObjectToString(evalue.mobile)+"</li>" +
								"<li class='w10' style='width:10%' title='"+convertObjectToString(evalue.position)+"'>"+convertObjectToString(evalue.position)+"</li>" +
								"<li class='w10' style='width:10%' title='"+convertObjectToString(evalue.department)+"'>"+convertObjectToString(evalue.department)+"</li>" +
								"<li class='w10' style='width:10%' title='"+convertObjectToString(evalue.company)+"'>"+convertObjectToString(evalue.company)+"</li>" +
								"<li class='w10' style='width:5%'><em style='margin-left:-10px;' onclick='changeState(this);' class='"+stateClass+"'></em></li>" +
								"<li class='s15-last no-right' style='width:15%'>" +
									"<a href='javascript:void(0);' class='edit0' onclick='showDialog(this);'  style='margin-left:-15px'>" +
										"<input type='hidden' value='"+evalue.companyId+"'/>" +
										"<input type='hidden' value='"+evalue.departmentId+"'/>" +
										"<input type='hidden' value='"+evalue.positionId+"'/>" +
										"<input type='hidden' value='"+evalue.state+"'/>" +
										"<input type='hidden' value='"+evalue.empno+"'/>" +
										"<input type='hidden' value='"+convertObjectToString(evalue.remark)+"'/>" +
									"</a>" +
									"<a href='javascript:void(0);'  class='delet1' onclick='deleteData(this);'style='margin-left:30px;vertical-align:-7px'></a>" +
									"<a href='javascript:void(0);'  class='shouquan' onclick='userAuthorize(this);' style='margin-left:20px'></a>" +
								"</li>" +
							"</ul>"+		
						"</div>";
			    
			});
		}
		if(1==isAuthorize){
			$(obj).parent().next().children().eq(6).hide();
		}else{
			$(obj).parent().next().children().eq(6).show();
		}
		$("#searchBody").html(html);
	}]);
}


function exportData(obj){
	$('.w-90').css({border:"none"});
	var exportFile = $(this).EXPT({
		name:'用户列表',
		yesBtnAct: function(callback,fname){
			var username = $('#JQ_username').val();
			var company = $("#SCompDiv").children().attr("id") =="gs" ? "" : $("#SCompDiv").children().attr("id");
			var department = $("#SDeptDiv").children().attr("id") =="bm" ? "" : $("#SDeptDiv").children().attr("id");
			var isAuthorize = $("#authorDiv").children().attr("id");
			$("input[name='username']").val(username);
			$("input[name='company']").val(company);
			$("input[name='department']").val(department);
			$("input[name='isAuthorize']").val(isAuthorize);
			$("input[name='fileName']").val(fname);
			$("#exportForm").submit();
			callback();
		}
	});


}

/**
 * @Title: showDialog   
 * @Description: 新增或修改用户
 * @param: @param obj      
 * @return: void      
 * @throws
 */
function showDialog(obj){
	if("add" == obj){
		$(".PopupTitle").html("新建用户信息");
		$("#userId").val("");
		$("#authorizeUser").val("");
		initView("#add");
		$(".open-off").children("input").val("LOCKED");
		$("#sexDiv").children().text("请选择性别");
		reslutLoad.findCompany(null,null,null);
		$("#add").modal("show");
	}else{
		$(".PopupTitle").html("修改用户信息");
		var companyId = $(obj).children().eq(0).val();
		var departmentId = $(obj).children().eq(1).val();
		var positionId = $(obj).children().eq(2).val();
		var state = $(obj).children().eq(3).val();
		if("LOCKED" != state){
			alert("该数据不允许修改");
		}else{
			$("#username").val($(obj).parent().parent().children("li").eq(1).html());
			$("#moblie").val($(obj).parent().parent().children("li").eq(5).html());
			$("#email").val($(obj).parent().parent().children("li").eq(4).html());
			$("#realName").val($(obj).parent().parent().children("li").eq(2).html());
			$("#code").val(convertObjectToString($(obj).children().eq(4).val()));
			$("#remark").val(convertObjectToString($(obj).children().eq(5).val()));
			$(".open-off").children("input").val(state);
			var sex = $(obj).parent().parent().children("li").eq(3).html();
			if("男" == sex){
				$("#sexDiv").children().text("男");
			}else{
				$("#sexDiv").children().text("女");
			}
			var userId = $(obj).parent().parent().find("span[name='checkSingle']").attr("id");
			$("#userId").val(userId);
			reslutLoad.findCompany(companyId,departmentId,positionId);
			$("#add").modal("show");
		}
	}
}

/**
 * 初始化新增弹出框
 */
function initView(obj){
	var obj = $(obj);
	obj.find("input").val("");
	obj.find("textarea").val("");
	obj.find(".open-off").children("em").removeClass();
	obj.find(".open-off").children("em").addClass("on-off");
	$("#sexDiv").children().text("性别");
	$("#companyDiv").children().text("请选择公司");
	$("#departmentDiv").children().text("请选择部门");
	$("#positionDiv").children().text("请选择岗位");
}

/**
 * @Title: save   
 * @Description: 新增或修改的保存
 * @param: @returns {Boolean}      
 * @return: Boolean      
 * @throws
 */
function save(){
	var regMobile = /^1[53874]\d{9}$/;
	var regEmail = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
	
	//用户名称
	var username = $.trim($("#username").val());
	//手机号码
	var mobile = $.trim($("#moblie").val());
	//邮箱
	var email = $.trim($("#email").val());
	//姓名
	var realName = $.trim($("#realName").val());
	//性别
	var sex = $("#sexDiv").children().text();
	//工号
	var code = $.trim($("#code").val());
	//公司
	var companyId = $("#companySelect").val();
	//部门
	var departmentId = $("#departmentSelect").val();
	//岗位
	var positionId = $("#positionSelect").val();
	//状态
	var state = $(".zhuangtai").children(".open-off").children("input").val();
	//备注
	var remark = $.trim($("#remark").val());
	//用户id
	var userId = $("#userId").val();
	
	if(!username){
		alert("请输入用户名称");
		return false;
	}
	if(!mobile || !mobile.match(regMobile)){
		alert("请输入有效的手机号码");
		return false;
	}
	if(!email || !email.match(regEmail)){
		alert("请输入有效的邮箱地址");
		return false;
	}
	if(!realName){
		alert("请输入姓名");
		return false;
	}
	if("男" != sex && "女" != sex){
		alert("请选择性别");
		return false;
	}
	if(!code ){
		alert("请输入工号");
		return false;
	}
	if(!companyId){
		alert("请选择公司");
		return false;
	}
	if(!departmentId){
		alert("请选择部门");
		return false;
	}
	if(!positionId){
		alert("请选择岗位");
		return false;
	}
	if(!state){
		alert("请设置用户状态");
		return false;
	}
	var data = {"username":username,"mobile":mobile,"email":email,"realName":realName,"sex":sex,"code":code,"id":userId,
			"companyId":companyId,"departmentId":departmentId,"positionId":positionId,"state":state,"remark":remark}
	$().invoke(pagePath + "/settings/user/saveUser.json",data,[function(m,r){
		if(1 == r){
			alert("保存成功");
			window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
		}
	}]);
}

/**
 * @Title: changeState   
 * @Description: 点击列表状态栏，改变用户状态  
 * @param: @param obj      
 * @return: void      
 * @throws
 */
function changeState(obj){
	var userId = $(obj).parent().parent().find("span[name='checkSingle']").attr("id");
	var boolean = $(obj).hasClass("active");
	var state = "";
	if("" == userId || undefined == userId){
		alert("数据异常，不允许的操作");
		return;
	}
	if(!boolean){
		state = "ACTIVATE";
	}else{
		state = "LOCKED";
	}
	window.cobj=obj;
	$().invoke(pagePath + "/settings/user/changeState.json",{"id":userId,"state":state},[function(m,r){
		if(1== r){
			$(window.cobj).parent().next().find("input").eq(3).val(state);
			if(!$(window.cobj).hasClass("active")){
				$(window.cobj).addClass("active");
			}else{
				$(window.cobj).removeClass("active");
			}
//			alert("操作成功");
		}
	}]);
}

/**
 * @Title: userAuthorize   
 * @Description: 点击列表 授权加载基本信息
 * @param: @param obj      
 * @return: void      
 * @throws
 */
function userAuthorize(obj){
	if('mutiple' == obj){
		$("#authorizeUser").val("");
		var count = 0;
		var userIdArr = new Array();
		var html = "";
		var userObj = $("#sh").find(".li1");
		var childBox = $("span[name=checkSingle]");
		for(var i= 0 ; i < childBox.length;i ++){
			if(childBox.eq(i).children().hasClass("active")){
				userIdArr.push(childBox.eq(i).attr("id"));
				html += "<span class='s1' style='margin-right:10px;width:auto;'>" +
					childBox.eq(i).parent().parent().next().html() +"("+childBox.eq(i).parent().parent().next().next().html() +")"+
						"</span><input type='hidden' value='"+childBox.eq(i).attr("id")+"' />";
				count++;
			}
		}
		if(userIdArr.length < 1){
			alert("请先勾选需要操作的数据");
			return ;
		}
		var idStr = userIdArr.join();
		$().invoke(pagePath + "/settings/user/userAuthorize.json",{"id":idStr},[function(m,r){
			var left = r.ug;
			var leftObj = $(".left-ch").children("ul").html('');
			$(".right-ch").children("ul").html("");
			for (var i = 0; i < left.length; i++) {
				leftObj.append("<li><input type='hidden' value='"+left[i].ID+"'/><span title='"+left[i].NAME+"'>"+left[i].NAME+"</span></li>");
			}
			
			userObj.html(html);
			authorize();
			$("#sh").modal("show");
		}]);
	}else{
		var userId = $(obj).parent().parent().find("span[name='checkSingle']").attr("id");
		var username = $(obj).parent().parent().find("li:eq(1)").html();
		if("" == userId || undefined == userId){
			alert("数据异常，不允许的操作");
			return;
		}
		$().invoke(pagePath + "/settings/user/userAuthorize.json",{"id":userId},[function(m,r){
			$("#authorizeUser").val(userId);
			$("#sh").find(".li1").html("<span class='s1'>"+username+"</span>");
//		if(r.ug.length > 0){
			var left = r.ug;
			var leftObj = $(".left-ch").children("ul");
			var rightObj = $(".right-ch").children("ul");
			var leftHtml ="";
			var rightHtml = "";
			var userGroup = r.userGroup;
			for (var i = 0; i < left.length; i++) {
				if(userGroup.indexOf(left[i].ID) != -1){
					rightHtml += "<li><input type='hidden' value='"+left[i].ID+"'/><span title='"+left[i].NAME+"'>"+left[i].NAME+"</span></li>";
				}else{
					leftHtml+= "<li><input type='hidden' value='"+left[i].ID+"'/><span title='"+left[i].NAME+"'>"+left[i].NAME+"</span></li>";
				}
			}
//		}
			leftObj.html(leftHtml);
			rightObj.html(rightHtml);
			authorize();
			$("#sh").modal("show");
		}]);
	}
	
}

/**
 * 
 * @Title: saveAuthorize   
 * @Description: 保存授权   
 * @param:       
 * @return: void      
 * @throws
 */
function saveAuthorize(){
	var userId = $("#authorizeUser").val();
	var dataList = $(".right-ch").children("ul").children();
	var str = "";
	var dataArr = new Array();
	var userIdArr = new Array();
	if("" == userId){
		var idObj = $("#sh").find(".li1").children("input");
		for (var int = 0; int < idObj.length; int++) {
			userIdArr.push(idObj.eq(int).val());
		}
		userId = userIdArr.join();
	}
	for (var i = 0; i < dataList.length; i++) {
		var data = $(".right-ch").children("ul").children("li").children("input").eq(i).val();
		dataArr.push(data);
	}
	str = dataArr.join(",");
	$().invoke(pagePath + "/settings/user/saveAuthorize.json",{"id":userId,"str":str},[function(m,r){
		if(r > 0){
			alert("操作成功");
			window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
		}
	}]);
}

/**
 *
 * @Title: deleteData   
 * @Description: 删除用户
 * @param: @param obj      
 * @return: void      
 * @throws
 */
function deleteData(obj){
	//获取所有name = childSelect的input
	var childBox = $("span[name=checkSingle]");
	if('multiple' == obj){
		var idsArr = new Array();
		var count = 0;
		for(var i= 0 ; i < childBox.length;i ++){
			if(childBox.eq(i).children().hasClass("active")){
				idsArr.push(childBox.eq(i).attr("id"));
				count++;
			}
		}
		if(idsArr.length < 1){
			alert("请先勾选需要删除的数据");
			return ;
		}
		var idStr = idsArr.join();
		var delFlag = window.confirm("确定要删除吗");
		if(delFlag == true){
			$().invoke(pagePath + "/settings/user/deleteData.json",{"idStr":idStr},[function(m,r){
				alert("已选择【"+count+"】条，成功删除【 "+r +" 】条");
				window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
			}]);
		}
	}else{
		var idStr= $(obj).parent().parent().find("span[name='checkSingle']").attr("id");
		var delFlag = window.confirm("确定要删除吗");
		if(delFlag == true){
			$().invoke(pagePath + "/settings/user/deleteData.json",{"idStr":idStr},[function(m,r){
				if(r == 0){
					alert("该记录已经不允许删除");
				}else{
					alert("删除成功");
					window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
				}
			}]);
		}
	}
}

/**
 * 
 * @Title: dataOnOrOff   
 * @Description: 启用或禁用用户
 * @param: @param opt      
 * @return: void      
 * @throws
 */
function dataOnOrOff(opt){
	var childBox = $("span[name=checkSingle]");
	var idsArr = new Array();
	var count = 0;
	for(var i= 0 ; i < childBox.length;i ++){
		if(childBox.eq(i).children().hasClass("active")){
			idsArr.push(childBox.eq(i).attr("id"));
			count++;
		}
	}
	if(idsArr.length < 1){
		alert("请先勾选需要操作的数据");
		return ;
	}
	var idStr = idsArr.join();
	var flag = window.confirm("确定要执行该操作吗");
	if(flag == true){
		$().invoke(pagePath + "/settings/user/dataOnOrOff.json",{"idStr":idStr,"opt":opt},[function(m,r){
//			var count = r;
			if("on" == opt){
				alert("已选择【"+count+"】条，成功启用【 "+r +" 】条");
			}else{
				alert("已选择【"+count+"】条，成功停用【 "+r +" 】条");
			}
			window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
		}]);
	}
}


function resetPwd(obj){
	var childBox = $("span[name=checkSingle]");
	var idsArr = new Array();
	var count = 0;
	for(var i= 0 ; i < childBox.length;i ++){
		if(childBox.eq(i).children().hasClass("active")){
			idsArr.push(childBox.eq(i).attr("id"));
			count++;
		}
	}
	if(idsArr.length < 1){
		alert("请先勾选需要操作的数据");
		return ;
	}
	var idStr = idsArr.join();
	var flag = window.confirm("确定要执行该操作吗");
	if(flag == true){
		$().invoke(pagePath + "/settings/user/resetPwd.json",{"idStr":idStr},[function(m,r){
			alert("已选择【"+count+"】条，成功为【 "+r+" 】位用户重置密码");
			window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
		}]);
	}
}


/**
 * 
 * @Title: getDepartment   
 * @Description: 根据公司获取部门   
 * @param: @param obj      
 * @return: void      
 * @throws
 */
function getDepartment(obj){
	var companyId = $(obj).children().attr("id");
	var html = "";
	var dept = $("#SDeptDiv").parent().next();
	dept.html("");
	$().invoke(pagePath + "/settings/user/ajaxGetDepartment.json",{"companyId":companyId},[function(m,r){
		var list = r;
		if(list.length > 0){
			$("#SDeptDiv").html("<a href='javascript:void(0);' id='bm'>请选择部门</a>");
			$.each(list,function(i,evalue){
				html += "<li><a href='javascript:void(0);' id='"+evalue.id+"'>"+evalue.name+"</a></li>";
			});
		}else{
			$("#SDeptDiv").html("<a href='javascript:void(0);' id='bm'>请选择部门</a>");
		}
		dept.html(html);
	}]);
}


function importData(){
	$("#dr").modal("show");
}

/**
 * 
 * @Title: progressFn   
 * @Description: 导入进度及相关信息   
 * @param: @param test      
 * @return: void      
 * @throws
 */
function progressFn(test){
	if(test=="-")
	{
		$(".jdt .go").css("width","100%")
	}else{
		var a = test.substring(0,test.indexOf("+"));
		var b=test.substring(0,test.indexOf(":"));
		var size=parseFloat(b.substring(1,b.indexOf("-")));
		$(".third span").html((size/1000).toFixed(2)+"kb");
		var z=test.substring(b.indexOf("-")+1,test.indexOf(":"));
		$(".jdt .go").css("width",""+(parseFloat(z.substring(0,z.indexOf("/")))/parseFloat(z.substring(z.indexOf("/")+1)))*100+"%");
		$(".no-info").append(test.substring(test.indexOf(":")+1));
		$(".no").next().children("i").html(a);
	}
}

function successFn(data){
	if(data.status == 0){
		$(".dr-list").html("");
		var html = "<ul><li><em class='ok'></em><span>导入跟踪记录成功！</span></li></ul>";
		$(".dr-list").html(html);
	}
}



function convertObjectToString(obj){
    return null==obj || "" == $.trim(obj) || undefined == obj ? "-" : obj;
}
function convertObjectToDate(obj){
    return null==obj || "" == $.trim(obj) || undefined == obj ? "-" : new Date(obj).Format("yyyy-MM-dd hh:mm:ss");
}


/**
 * @Title: authorize   
 * @Description: 授权js操作
 * @param:       
 * @return: void      
 * @throws
 */
function authorize(){
	 $('.right-ch li').on('click',function(){
         $(this).addClass('active');
     })
     $('.left-ch li').on('click',function(){
         $(this).addClass('active');
     })
     $('.left-icon').on('click',function(){

         $('.right-ch ul ').append($('.left-ch ul li.active'));
         $('.right-ch ul li.active').removeClass("active");
     })
     $('.right-icon').on('click',function(){
         $('.left-ch ul ').append($('.right-ch ul li.active'));
         $('.left-ch ul li.active').removeClass("active");
     })
}


/************         公司-部门-岗位 联动开始          **********/
var reslutLoad = {
		findCompany:function(companyId,departmentId,positionId){
			$().invoke(pagePath + "/settings/user/ajaxGetCompany.json",{},[function(m,r){
				companyFun(m,r,companyId,departmentId,positionId);
			}]);
		},
		findDept:function(departmentId,positionId){
			var companyId = $("#companySelect").val();
			$().invoke(pagePath + "/settings/user/ajaxGetDepartment.json",{"companyId":companyId},[function(m,r){
				departmentFun(m,r,departmentId,positionId);
			}]);
		},
		findPosition:function(positionId){
			var departmentId = $("#departmentSelect").val();
			$().invoke(pagePath + "/settings/user/ajaxGetPosition.json",{"departmentId":departmentId},[function(m,r){
				positionFun(m,r,positionId);
			}]);
		},
		clearPosition:function(){
			$("#position").parent().parent().next("ul").find("li").remove();
		}
}

function companyFun(m,r,companyId,departmentId,positionId){
	var company =  $("#company").parent().parent().next("ul");
	if(null != r){
		company.html("");
		for (var i = 0; i < r.length; i++) {
			var li = "<li onclick='companyChange(this);'><input type='hidden' value='"+r[i].id+"'/><a href='javascript:void(0);'>"+r[i].name+"</a></li>";
			company.append(li);
		}
		if(companyId){
			var liList = company.children();
			for (var i = 0; i < liList.length; i++) {
				var selVal = $(liList[i]).children("input").val();
				if(selVal == companyId){
					$("#company").text($(liList[i]).children("a").text());
					$("#companySelect").val(selVal);
					break;
				}
			}
			reslutLoad.findDept(departmentId,positionId);
		}
	}
}

function departmentFun(m,r,departmentId,positionId){
	var department = $("#department").parent().parent().next("ul");
	if(null != r){
		department.html("");
		$("#department").text("请选择部门");
		$("#position").text("请选择岗位");
		
		for (var i = 0; i < r.length; i++) {
			var li = "<li onclick='departmentChange(this);'><input type='hidden' value='"+r[i].id+"'/><a href='javascript:void(0);' >"+r[i].name+"</a></li>";
			department.append(li);
		}
		if(departmentId){
			var liList = department.children();
			for (var i = 0; i < liList.length; i++) {
				var selVal = $(liList[i]).children("input").val();
				if(selVal == departmentId){
					$("#department").text($(liList[i]).children("a").text());
					$("#departmentSelect").val(selVal);
					break;
				}
			}
			reslutLoad.findPosition(positionId);
		}
	}
}

function positionFun(m,r,positionId){
	var position = $("#position").parent().parent().next("ul");
	if(null != r){
		position.html("");
		$("#position").text("请选择岗位");
		for (var i = 0; i < r.length; i++) {
			if(r[i]){
				var li = "<li onclick='positionChange(this)'><input type='hidden' value='"+r[i].id+"'/><a href='javascript:void(0);'>"+r[i].name+"</a></li>";
				position.append(li);
			}
		}
		if(positionId){
			var liList = position.children();
			for (var i = 0; i < liList.length; i++) {
				var selVal = $(liList[i]).children("input").val();
				if(selVal == positionId){
					$("#position").text($(liList[i]).children("a").text());
					$("#positionSelect").val(selVal);
					break;
				}
			}
		}
	}
}

function companyChange(obj){
	$("#companySelect").val(obj.firstChild.value);
	$(obj).children("a").attr("id","company");
	$("#departmentDiv").children().attr("id","department");
	$("#positionDiv").children().attr("id","position");
	$("#departmentSelect").val("");
	$("#positionSelect").val("");
	reslutLoad.findDept();
	reslutLoad.clearPosition();
}

function departmentChange(obj){
	$("#departmentSelect").val(obj.firstChild.value);
	$(obj).children("a").attr("id","department");
	$("#positionDiv").children().attr("id","position");
	$("#positionSelect").val("");
	reslutLoad.findPosition();
}

function positionChange(obj){
	$("#positionSelect").val(obj.firstChild.value);
	$(obj).children("a").attr("id","position");
}
/************         公司-部门-岗位 联动结束          **********/